Skip to content

Conversation

@gabrycina
Copy link
Contributor

Summary

Adds cursor-based pagination support to match backend API changes.

Breaking Change

messages.list() now returns PaginatedMessagesResponse:

# Before
messages = client.messages.list(task_id=task_id)
for m in messages: ...

# After
response = client.messages.list(task_id=task_id)
for m in response.data: ...

Changes

  • Add cursor and direction params to MessageListParams
  • Add PaginatedMessagesResponse type with data, next_cursor, has_more
  • Update list() method signature in Messages resource
  • Update tests for new response format

Related PRs

BREAKING CHANGE: messages.list() now returns PaginatedMessagesResponse
with {data, next_cursor, has_more} instead of list[TaskMessage].

Changes:
- Add cursor and direction params to MessageListParams
- Add PaginatedMessagesResponse type with data, next_cursor, has_more
- Update list() method signature in Messages resource
- Update tests for new response format
Backwards-compatible change:
- Original messages.list() unchanged (returns List[TaskMessage])
- New messages.list_paginated() for cursor pagination (returns PaginatedMessagesResponse)
- MessageListParams and MessageListPaginatedParams split for clarity
MichaelSun48 pushed a commit to scaleapi/scale-agentex that referenced this pull request Dec 9, 2025
## Summary

Implements cursor-based pagination for the `/messages` endpoint to
enable infinite scroll in the UI.

### Breaking Change

`GET /messages` now returns `PaginatedMessagesResponse` instead of raw
array:
```json
{ "data": [...], "next_cursor": "...", "has_more": true }
```

### Backend Changes
- Add `cursor` and `direction` query params to `/messages`
- Return `{data, next_cursor, has_more}` response format
- Add `pagination.py` with cursor encode/decode utilities
- Add `find_by_field_with_cursor()` to MongoDB adapter

### Frontend Changes
- Replace `useTaskMessages` with `useInfiniteTaskMessages` hook
- Implement infinite scroll with IntersectionObserver
- Add scroll position preservation when loading older messages
- Fix Thinking indicator timing
- Remove deprecated `custom-subscribe-task-state.tsx`

### Related PRs
- TypeScript SDK: TBD
- Python SDK: scaleapi/scale-agentex-python#222

### Suggested Deployment Order
1. Deploy this PR (backend)
2. Publish TypeScript SDK
3. Publish Python SDK
4. Deploy frontend (after updating SDK version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants